package com.jiatuxueyuan.redis.demo1;

import org.redisson.Redisson;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisKeyValueTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import redis.clients.jedis.JedisPoolConfig;

import java.util.concurrent.TimeUnit;

//@SpringBootApplication
public class RedisDemo1Application {

    public static void main(String[] args) {

        JedisPoolConfig cfg = new JedisPoolConfig();

        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.opsForValue().setIfAbsent(1421, "greate");//setnx指令，用redis来实现分布式锁
        redisTemplate.opsForValue().setIfAbsent(1421, "greate", 10, TimeUnit.SECONDS);
//        redisTemplate.expire(1421, 10, TimeUnit.SECONDS);//30秒自动过期失效

        Config config = new Config();
        config.useSingleServer().setAddress("redis://r-bp1ytl665ni743ubz0pd.redis.rds.aliyuncs.com:6379").setPassword("redisA888");
        RedissonClient redisson = Redisson.create(config);

        RMap<String, Object> map1 = redisson.getMap("map1");
        map1.put("username", "崔文俊");
        map1.putIfAbsent("age", 38);

        redisson.shutdown();


    }

}
